home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- *
- * Copyright © 1990 Apple Computer, Inc. All rights reserved.
- *
- ************************************************************************/
-
- #include <stdio.h>
- #include <strings.h>
- #include <Dialogs.h>
- #include <Windows.h>
- #include <Fonts.h>
- #include <Files.h>
- #include <Resources.h>
- #include <Memory.h>
-
- #include "mydialog.h"
- #include "textdlog.h"
- #include "DialogUtils.h"
- #include "mydialog.proto.h"
-
- #define VOLNAME_DIALOG 256
- #define DESTROY_DIALOG 257
- #define FirstButton 1
- #define SecondButton 2
- #define StringField 3
-
- static void strcpy255(char *dst, char *src);
-
- extern void strcpy255(char *, char *);
-
-
- /************************************************************************
- *
- * Function: strcpy255
- *
- * Purpose: copy a string
- *
- * Returns: nothing
- *
- * Side Effects: copies *src into *dst
- *
- * Description: loop copying until we hit the null byte of src.
- * We stop copying if we try to copy more than 255
- * chars at a time.
- *
- ************************************************************************/
- static void
- strcpy255(char *dst, char *src)
- {
- short i = 0;
- while ( ( (*dst++ = *src++) != 0) & (i++ < 255) )
- /* nothing */ ;
- }
-
- /************************************************************************
- *
- * Function: AskForString
- *
- * Purpose: ask the user for a string.
- *
- * Returns: Boolean
- * true if the user entered something
- * false if the user asked to cancel out
- *
- * Side Effects:
- * theString is filled with a C string if we return true.
- *
- * Description:
- * put up a dialog.
- *
- ************************************************************************/
- Boolean
- AskForString(char *prompt, char *theString)
- {
- DialogPtr dPtr;
- short result;
-
- short unusedType; /* for hiliting okay button */
- Handle hItem;
- Rect dBox;
-
- Boolean leaveYet;
-
- Str255 enteredString;
-
- dPtr = GetNewDialog(DU_CenterDLOG(VOLNAME_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
-
- HighLightDefault(dPtr); /* hilite OK button */
-
- SelIText(dPtr, StringField, 0, 999); /* all of the string field selected */
-
- ParamText((StringPtr)prompt, NULL, NULL, NULL);
-
- leaveYet = false;
- do
- {
- HighLightDefault(dPtr);
- ModalDialog(0, &result);
- if (result == FirstButton)
- leaveYet = true;
- if (result == SecondButton)
- {
- SysBeep(1);
- leaveYet = true;
- return false;
- }
- } while (leaveYet == false);
-
-
- GetDItem(dPtr, StringField, &unusedType, &hItem, &dBox);
- GetIText(hItem, (StringPtr)&enteredString);
- strcpy255(theString, P2CStr((StringPtr)&enteredString));
- DisposDialog(dPtr);
- return true;
- }
-
- /************************************************************************
- *
- * Function: AskDestroyDisk
- *
- * Purpose: Check that you really want to nuke a disk
- *
- * Returns: Boolean
- * true = yes, destroy it
- * false = no, leave it alone, it was a mistake.
- *
- * Side Effects: none.
- *
- * Description: display our warning about destroying a disk.
- * Ask, using a modal dialog, whether the user really
- * wants to lose it. (Default button is cancel, since
- * this is such a permanent thing...)
- *
- *
- ************************************************************************/
- Boolean
- AskDestroyDisk(short gDriveNumber)
- {
- DialogPtr dPtr;
- short result;
- Boolean leaveYet;
- Boolean okayToDestroy;
-
- Str255 volumeName;
- short vRefNum;
- long freeBytes;
-
- okayToDestroy = true;
- dPtr = GetNewDialog(DU_CenterDLOG(DESTROY_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
-
- HighLightDefault(dPtr);
-
- if (GetVInfo(gDriveNumber, volumeName, &vRefNum, &freeBytes) != noErr)
- okayToDestroy = false;
-
- if (okayToDestroy)
- {
- ParamText((StringPtr)volumeName, NULL, NULL, NULL);
-
- leaveYet = false;
- do
- {
- HighLightDefault(dPtr);
- ModalDialog(0, &result);
- if (result == SecondButton)
- leaveYet = true;
- if (result == FirstButton)
- {
- SysBeep(1);
- leaveYet = true;
- okayToDestroy = false;
- }
- } while (leaveYet == false);
- }
-
- DisposDialog(dPtr);
- return okayToDestroy;
- }
-
-
-
- /************************************************************************
- *
- * Function: Help
- *
- * Purpose: explain what we're doing
- *
- * Returns: void
- *
- * Side Effects: none.
- *
- * Description: display our help text. Currently always returns true.
- *
- *
- ************************************************************************/
- Boolean
- Help(void)
- {
- Handle tHandle;
-
- tHandle = GetResource('TEXT', 1001);
- if (tHandle != (Handle)0)
- {
- HLock(tHandle);
- TextDialog(1001, tHandle, times, 12, true);
- HUnlock(tHandle);
- ReleaseResource(tHandle);
- }
- return true;
- }
-
-